<template>
	<view class="login-wrapper">
		<view class="head-wrapper">
			<view class="fh">
				<u-icon name="arrow-left" color="white" size="20" @click="fh()"></u-icon>
			</view>
			<view class="conten">
				<view class="title">{{visiable ? "注册" : "登录" }}</view> <br>
				<input class="name" v-model="obj.username" maxlength="10" placeholder="请输入用户名" />
				<input class="name" v-model="obj.password" maxlength="10" placeholder="请输入密码" />
				<input class="name" v-model="obj.repassword" maxlength="10" placeholder="请再次确认密码" v-show="visiable" />

				<view class="btn" @click="loginbtn">
					{{visiable ? "注册" : "登录" }}
				</view>
				<view class="zhu">
					<view class="zc" @click="show">{{visiable ? "去登录" : "注册" }}账号</view>
					<view class="wj">忘记密码 ？</view>
				</view>
				<view class="yue">
					<label @click="ischeck = !ischeck">
						<checkbox v-model="ischeck" /><text></text>
					</label>
					已阅读并同意用户协议&隐私声明
				</view>
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
		<u-toast ref="uToast"></u-toast>
		<u-cell-group title-bg-color="rgb(243, 244, 246)">
			<u-cell :titleStyle="{fontWeight: 500}" :title="item.title" v-for="(item, index) in list" :key="index"
				isLink :icon="item.iconUrl" @click="showToast(item)">
			</u-cell>
		</u-cell-group>
	</view>
</template>

<script>
	import {
		loginList, //登录
		zcList
	} from "../api/login.js"
	export default {
		data() {
			return {
				visiable: false,
				obj: {
					password: "",
					repassword: "",
					username: "",
				},

				ischeck: false
			}
		},
		methods: {
			//返回上一级
			fh() {
				uni.navigateBack({
					delta: 1
				})
			},
			// 显示框
			show() {
				this.visiable = !this.visiable
			},
			//登录
			async loginbtn() {
				if (this.ischeck == false) {

					this.$refs.uToast.show({
						type: 'default',
						message: "请同意用户协议",
					})
					return
				}

				const res = await (this.visiable == false ? loginList : zcList)(this.obj)
				console.log(res, "登录")
				if (res.data.msg === "ok") {
					wx.setStorageSync("token", res.data.data.token)
					wx.setStorageSync("user", res.data.data)
					uni.switchTab({
						url: "../mymine/mymine"
					})
					this.$refs.uToast.show({
						type: 'default',
						message: this.visiable == false ? "登录成功" : "注册成功",
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.login-wrapper {
		width: 100%;
		height: 100%;
		overflow: hidden;
		background-image: linear-gradient(120deg, #3bfdaf, #70d6f2);

		.head-wrapper {
			width: 100%;
			height: 250rpx;
			background-image: linear-gradient(120deg, #3bfdaf, #70d6f2);

			.fh {
				margin-top: 60rpx;
				box-sizing: border-box;
				height: 80rpx;
				display: flex;
				align-items: center;
				padding-left: 40rpx;
			}
		}

		.conten {
			width: 100%;
			height: 100%;
			position: absolute;
			top: 204rpx;
			left: 0;
			right: 0;
			background-color: #fff;
			border-top-left-radius: 100rpx;
			border-top-right-radius: 100rpx;
			padding: 61rpx 71rpx 0 71rpx;
			box-sizing: border-box;


			.name {
				margin-top: 30rpx;
				margin-bottom: 30rpx;
				border-radius: 5rpx;
				padding-left: 20rpx;
				height: 80rpx;
				font-size: 30rpx;
				background-color: gainsboro;
			}

			.yue {
				margin-top: 30rpx;
				height: 90rpx;
				width: 100%;
				font-size: 30rpx;
				color: #a9a5a0;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.zhu {
				margin-top: 30rpx;
				height: 90rpx;
				width: 100%;
				border-radius: 10rpx;
				font-size: 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				color: #5ccc84;

				.wj {
					color: #a9a5a0;
				}
			}

			.btn {
				height: 90rpx;
				width: 100%;
				border-radius: 10rpx;
				font-size: 33rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				color: white;
				background-color: #5ccc84;
			}

			.title {
				font-size: 35rpx;
			}

			.u--input {
				background-color: #3bfdaf;
			}
		}
	}
</style>
